package com.shirley.customcontrols;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shirley.slidemenu.SlideMenuView;
import com.shirley.slidemenu.entity.Category;
import com.shirley.slidemenu.entity.CategoryContent;
import com.shirley.slidemenu.entity.Content;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 主界面的Tab2对应的fragment
 * Created by ZLJ on 2017/12/18.
 */
public class SlideMenuFragment extends Fragment {

    Unbinder unbinder;
    @BindView(R.id.slide_menu_view)
    SlideMenuView slideMenuView;

    private int[][] mImgResId = {
            { R.drawable.img1, R.drawable.img2 },
            { R.drawable.img3, R.drawable.img4 }
    };

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_slide_menu, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        slideMenuView.setData(constructFakeData());
        /*slideMenuView.setOnContentClickListener(new SlideMenuView.OnContentClickListener() {
            @Override
            public void onContentClick(int position, ContentCategory data) {
                Toast.makeText(getContext(), data.getContent().getDesc(), Toast.LENGTH_SHORT).show();
            }
        });*/
    }

    private List<CategoryContent> constructFakeData() {
        List<CategoryContent> data = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            CategoryContent categoryContent = new CategoryContent();
            categoryContent.setCategory(new Category("Category " + i));
            List<Content> contentList = new ArrayList<>();
            for (int j = 0; j < 4; j++) {
                Content content = new Content("content " + i + "-" + j);
                if (i < mImgResId.length && j < mImgResId[i].length){
//                    content.setImg(BitmapFactory.decodeResource(getResources(), mImgResId[i][j]));
                }
                contentList.add(content);
            }
            categoryContent.setContents(contentList);
            data.add(categoryContent);
        }
        return data;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
